home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / dev / gui / pmdev.lha / PopupMenuDeveloper / Demos / InControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-22  |  4.1 KB  |  149 lines

  1. //
  2. // $VER: InControl.c 1.0 (7.3.97)
  3. //
  4. // Popup Menu example program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Click the little button in the top left of your screen!
  10. //
  11.  
  12. #include <intuition/intuition.h>
  13.  
  14. #include <clib/intuition_protos.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. #include <libraries/pm.h>
  23. #include <proto/pm.h>
  24.  
  25. struct IntuitionBase    *IntuitionBase;
  26. struct GfxBase        *GfxBase;
  27. struct PopupMenuBase    *PopupMenuBase;
  28.  
  29. struct Window *w;    // This window is only needed to find out when and where the menu should appear.
  30.             // The font in this window's rastport will be used for the menu.
  31.  
  32. void main()
  33. {
  34.     BOOL r=TRUE;
  35.     struct IntuiMessage *im,imsg;
  36.     struct PopupMenu *p;
  37.  
  38.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  39.     if(PopupMenuBase) {
  40.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  41.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  42.  
  43.         p=PM_MakeMenu(    // Create a menu. This menu should actually be read from a config file, but it's just demo!
  44.             PMItem("Internet"),
  45.                 PMSubMenu("Internet"),
  46.                     PMItem("Miami"),        PM_UserData,    20,    End,
  47.                     PMItem("YAM"),            PM_UserData,    21,    End,
  48.                     PMItem("IBrowse"),        PM_UserData,    22,    End,
  49.                     PMItem("AmFTP"),        PM_UserData,    23,    End,
  50.                     PMItem("AmIRC"),        PM_UserData,    24,    End,
  51.                 End,
  52.             End,
  53.             PMTitleBar,                        End,
  54.             PMItem("CEd"),            PM_UserData,    25,    End,
  55.             PMItem("DPaint"),        PM_UserData,    26,    End,
  56.             PMItem("CLI"),            PM_UserData,    27,    End,
  57.             PMItem("DosTrace"),        PM_UserData,    28,    End,
  58.             PMItem("ARTM"),            PM_UserData,    29,    End,
  59.             PMTitleBar,                        End,
  60.             PMItem("Exit InControl"),    PM_UserData,    5,    End,
  61.             PMTitleBar,                        End,
  62.             PMItem("Reboot"),        PM_UserData,    10,    End,
  63.             End;
  64.  
  65.         if(p) {
  66.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  67.                     WA_RMBTrap,    TRUE,
  68.                     WA_DragBar,    TRUE,
  69.                     WA_Top,        0,
  70.                     WA_Left,    0,
  71.                     WA_Width,    19,
  72.                     WA_Height,    11,
  73.                     WA_Borderless,    TRUE,
  74.                     WA_CloseGadget,    TRUE,
  75.                     TAG_DONE);
  76.             if(w) {
  77.  
  78.                 w->WScreen->BarHBorder=25;    // This will move the text in the screenbar next time it is redrawn
  79.                                 // Unfortunately it will also mess up the menus...
  80.                                 // Mail me if you know a better way to move the screentitle!
  81.  
  82.                 while(r) {
  83.                     WaitPort(w->UserPort);                        // Wait for a message
  84.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  85.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  86.                         ReplyMsg((struct Message *)im);                // Reply the message
  87.  
  88.                         switch(imsg.Class) {
  89.                             case IDCMP_CLOSEWINDOW:
  90.                             case IDCMP_MOUSEBUTTONS:
  91.                                 r=(BOOL)PM_OpenPopupMenu(w,
  92.                                         PM_Menu,        p,
  93.                                         PM_Left,        10,
  94.                                         PM_Top,            12,
  95.                                         PM_WideSelectBar,    TRUE,
  96.                                         PM_RecessSelected,    TRUE,
  97.                                         PM_Code,        imsg.Code,
  98.                                         TAG_DONE);
  99.                                 switch(r) {
  100.                                     case 5:
  101.                                         r=0;
  102.                                         break;
  103.                                     case 0:
  104.                                         r=10;
  105.                                         break;
  106.                                     case 10:
  107.                                         break;
  108.                                     case 20:
  109.                                         system("RUN <>NIL: COMM:MIAMI/MIAMI");
  110.                                         break;
  111.                                     case 21:
  112.                                         system("RUN <>NIL: COMM:YAM/YAM");
  113.                                         break;
  114.                                     case 22:
  115.                                         system("RUN <>NIL: COMM:IBROWSE/IBROWSE");
  116.                                         break;
  117.                                     case 23:
  118.                                         system("RUN <>NIL: COMM:AMFTP/AMFTP");
  119.                                         break;
  120.                                     case 24:
  121.                                         system("RUN <>NIL: COMM:AMIRC/AMIRC");
  122.                                         break;
  123.                                     case 25:
  124.                                         system("RUN <>NIL: CED");
  125.                                         break;
  126.                                     case 26:
  127.                                         break;
  128.                                     case 27:
  129.                                         system("RUN <>NIL: NewCLI");
  130.                                         break;
  131.                                     case 28:
  132.                                         system("RUN <>NIL: DOSTRACE");
  133.                                         break;
  134.                                     case 29:
  135.                                         system("RUN <>NIL: ARTM");
  136.                                         break;
  137.                                 }
  138.                             break;
  139.                         }
  140.                     }
  141.                 }
  142.                 CloseWindow(w);
  143.             } else printf("Window error!\n");
  144.             PM_FreePopupMenu(p);
  145.         } else printf("Menu error!\n");
  146.         CloseLibrary((struct Library *)PopupMenuBase);
  147.     }
  148. }
  149.